<!DOCTYPE html>
<html>

<head lang="en">
    <title>登录</title>
    <#include "/boya/template/meta.html" />
</head>

<body>
    <div id="app">
        <div class="header">
            <div class="am-g">
                <h1>登录</h1>
                <p></p>
            </div>
            <hr />
        </div>
        <div class="am-g">
            <div class="am-u-lg-6 am-u-md-8 am-u-sm-centered">
                <form method="post" class="am-form">
                    <label for="account">账号:</label>
                    <input type="text" id="account" v-model="account">
                    <br>
                    <label for="password">密码:</label>
                    <input type="password" id="password" v-model="password" @keyup.enter="submit">
                    <br>
                    <!-- <label for="remember-me">
                      <input id="remember-me" type="checkbox">
                      记住密码
                    </label> -->
                    <br />
                </form>
                <div class="am-cf">
                    <button class="am-btn am-btn-primary am-btn-sm am-fl" @click="submit">登 录</button>
                </div>
                <hr>
                <p>由
                    <a href="http://www.zhen-yee.com/" title="蓁奕科技" target="_blank" style="color: #0e90d2;">蓁奕科技</a>
                    提供技术支持 CopyRight©2018 Zhenyi Tech Inc.</p>
            </div>
        </div>
    </div>
    <#include "/boya/template/script.html" />
    <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9/crypto-js.min.js"></script> -->
    <script src="//res.zhen-yee.com/assert/crypto-js.3.1.9.min.js"></script>
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data() {
            return {
                account: '',
                password: ''
            }
        },
        methods: {
            submit() {
                var self = this;
                var encoded = self.aesCBC(self.password);
                var param = Qs.stringify({
                    account: self.account,
                    password: encoded
                });
                axios({
                    url: '/boya/login',
                    method: 'post',
                    data: param,
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                .then(function(response) {
                    if (response.data.status == 200) {
                        if (response.data.info.role == 1) {
                            window.location.href = "/boya/";
                        } else {
                            window.location.href = "/boya/importList";
                        }
                        // msg("登录成功");
                    } else {
                        msg("登录失败：" + response.data.msg);
                        console.log(response.data);
                    }
                })
                .catch(function(error) {
                    msg("登录失败");
                    console.log(error);
                });
            },
            aesCBC(text) {
                var self = this;
                var aesText = text;
                var key = CryptoJS.enc.Utf8.parse('boya!@#$%^&*()_+');
                var iv = CryptoJS.enc.Utf8.parse('RandomInitVector');
                aesText = CryptoJS.AES.encrypt(text, key, {
                    iv: iv,
                    mode: CryptoJS.mode.CBC,
                    padding: CryptoJS.pad.Pkcs7
                }).toString();
                return aesText;
            }
        }
    })
    </script>
    <style>
    .header {
        text-align: center;
    }

    .header h1 {
        font-size: 200%;
        color: #333;
        margin-top: 30px;
    }

    .header p {
        font-size: 14px;
    }
    </style>
</body>

</html>